package com.hivis.controller;

import com.alibaba.fastjson.JSON;
import com.hivis.utils.PropertyUtil;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/api/version")
public class AppVersionController {
    @ResponseBody
    @RequestMapping(value = "get", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    public String getVersion(HttpServletRequest request) {
        PropertyUtil.loadProps("app-version.properties");
        String version = PropertyUtil.getProperty("vipface.app.version.code");
        Map<String, Integer> resp = new HashMap<>();
        if(!StringUtils.isEmpty(version)) resp.put("versionCode", Integer.valueOf(version));

        return JSON.toJSONString(resp);
    }
}
